﻿using System;
using System.Windows.Data;
using BizControl.Library.BusinessObjects.Activities;
using BizControl.Library.Helpers;

namespace BizControl.Presentation.ActivityEditModule.Converters
{
  public class ActivityRatingToTextConverter : IMultiValueConverter
  {
    private readonly int _isHoveringIndex = 2;
    private readonly int _valueIndex = 0;
    private readonly int _hoverValueIndex = 1;

    #region IMultiValueConverter Members

    public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
      int val;
      if (bool.Parse(values[_isHoveringIndex].ToString()))
        val = int.Parse(values[_hoverValueIndex].ToString());
      else
        val = int.Parse(values[_valueIndex].ToString());
      if (val == (Int32)ActivityQualityRating.Bad) return ActivityQualityRating.Bad.GetLocalizedDescription();
      if (val == (Int32)ActivityQualityRating.Good) return ActivityQualityRating.Good.GetLocalizedDescription();
      if (val == (Int32)ActivityQualityRating.Excellent) return ActivityQualityRating.Excellent.GetLocalizedDescription();
      return string.Empty;
    }

    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
    {
      return null;
    }

    #endregion
  }
}
